home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / OrganicLabelUI.java < prev    next >
Text File  |  1998-06-30  |  3KB  |  116 lines

  1. /*
  2.  * @(#)OrganicLabelUI.java    1.5 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.organic;
  22.  
  23. import com.sun.java.swing.*;
  24. import java.awt.Container;
  25. import java.awt.Dimension;
  26. import java.awt.Rectangle;
  27. import java.awt.Insets;
  28. import java.awt.Color;
  29. import java.awt.Graphics;
  30. import java.awt.Font;
  31. import java.awt.FontMetrics;
  32. import com.sun.java.swing.plaf.*;
  33. import com.sun.java.swing.plaf.basic.BasicLabelUI;
  34.  
  35.  
  36.  
  37. /**
  38.  * A Java L&F implementation of LabelUI.  This implementation 
  39.  * is completely static, i.e. there's only one UIView implementation 
  40.  * that's shared by all JLabel objects.
  41.  * <p>
  42.  * Warning: serialized objects of this class will not be compatible with
  43.  * future swing releases.  The current serialization support is appropriate
  44.  * for short term storage or RMI between Swing1.0 applications.  It will
  45.  * not be possible to load serialized Swing1.0 objects with future releases
  46.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  47.  * baseline for the serialized form of Swing objects.
  48.  *
  49.  * @version 1.5 02/02/98
  50.  * @author Tom Santos
  51.  */
  52. public class OrganicLabelUI extends BasicLabelUI
  53. {
  54.     private static final OrganicLabelUI organicLabelUI = new OrganicLabelUI();
  55.  
  56.  
  57.     public static ComponentUI createUI(JComponent c) {
  58.     return organicLabelUI;
  59.     }
  60.  
  61.     public void paint(Graphics g, JComponent c) 
  62.     {
  63.     JLabel label = (JLabel)c;
  64.     String text = label.getText();
  65.  
  66.     Icon icon;
  67.     if(label.isEnabled()) {
  68.         icon = label.getIcon();
  69.     } else {
  70.         icon = label.getDisabledIcon();
  71.     }
  72.  
  73.     if ((icon == null) && (text == null)) {
  74.         return;
  75.     }
  76.  
  77.     FontMetrics fm = g.getFontMetrics();
  78.     Rectangle iconR = new Rectangle();
  79.     Rectangle textR = new Rectangle();
  80.     Rectangle viewR = new Rectangle(c.getSize());
  81.     Insets viewInsets = c.getInsets();
  82.  
  83.     viewR.x = viewInsets.left;
  84.     viewR.y = viewInsets.top;
  85.     viewR.width -= (viewInsets.left + viewInsets.right);
  86.     viewR.height -= (viewInsets.top + viewInsets.bottom);
  87.  
  88.     String clippedText = layoutCL(label, fm, text, icon, viewR, iconR, textR);
  89.  
  90.     if (label.isOpaque()) {
  91.         g.setColor(label.getBackground());
  92.         g.fillRect(0, 0, label.getWidth(), label.getHeight());
  93.     }
  94.  
  95.     if (icon != null) {
  96.         icon.paintIcon(c, g, iconR.x, iconR.y);
  97.     }
  98.  
  99.     if (text != null) {
  100.         int textX = textR.x;
  101.         int textY = textR.y + fm.getAscent();
  102.         int accChar = label.getDisplayedMnemonic();
  103.  
  104.         if (label.isEnabled()) {
  105.         g.setColor(label.getForeground());
  106.         }
  107.         else {
  108.             g.setColor( UIManager.getColor("Label.disabled") );
  109.         }
  110.  
  111.         OrganicUtilities.drawString(g, clippedText, accChar, textX, textY);
  112.     }
  113.     }
  114. }
  115.  
  116.